// import * as React from 'react';
import React, { useState, useEffect, useRef } from 'react';
import './psDetail.less';
import {
  Input,
  Descriptions,
  Button,
  Table,
  DatePicker,
  Form,
  Select,
} from 'antd';
import { Link, useRequest } from 'umi';

const { Option } = Select;
import { UploadOutlined } from '@ant-design/icons';
import styles from '@/pages/admin/mark/personScore.less';
import request from '@/http';

const { RangePicker } = DatePicker;
export default (props: any) => {
  const courseId: number = props.location.state.courseId;
  const teamId: number = props.location.state.teamId;

  console.log(courseId);
  console.log(teamId);
  console.log(props.location.state.comments);
  const dataDetail = props.location.state;
  const [formObject] = Form.useForm();

  const [dataSource, setDataSource] = useState<any[]>([]);
  const [teacher, setTeacher] = useState<any[]>([]);
  const [teamMembers, setTeamMembers] = useState<any[]>([]);

  const loadDataSource = async () => {
    const result: any = await request.get(
      '/api/admin/adminScore/getTrainTeachersAndTeamMembers?teamId=' +
        teamId +
        '&courseId=' +
        courseId,
    );

    if (result && result.code === 200) {
      setTeacher(result.data.trainTeachers);
      setTeamMembers(result.data.teamMembers);
    }
  };

  //个人历史作业  下面table
  const allWork = async () => {
    const result: any = await request.get(
      '/api/admin/adminScore/getTeamHomeWork?size=5&current=1&teamId=' +
        teamId +
        '&courseId=' +
        courseId,
    );
    console.log(result);
    if (result && result.code === 200) {
      const data: any = result.data.records.map((user: any) => ({
        key: `user_${user.homeworkDetailsId}`,
        id: user.homeworkDetailsId, // id
        homeworkDetailsId: user.homeworkDetailsId, // 作业id
        title: user.title, // 	作业主题
        issuedTime: user.issuedTime, // 作业发布时间
        score: user.score, // 	得分
        submitStatus: user.submitStatus, // 	作业提交情况
        stuId: user.stuId, // 学生id
        teacherName: user.teacherName, // 作业发布老师
        actualSubmitTime: user.actualSubmitTime, //	完成时间
        submitTime: user.submitTime, //	作业截止日期
      }));
      setDataSource(data);
      // console.log('dataSource5',dataSource);
    }
  };

  //生命周期函数
  useEffect(() => {
    loadDataSource();
    allWork();
  }, []);

  return (
    <>
      <div className="absence_title" style={{ marginBottom: '30px' }}>
        <div className="search" style={{ width: '1400px', height: '380px' }}>
          <div className="title">小组综合得分</div>
          <div className={styles.searchForm}>
            {
              <>
                <Form layout="inline" className="psdForm">
                  <Form.Item
                    style={{ width: 300 }}
                    label="小&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;组"
                    name="teamName"
                  >
                    {/*<Input className='teacherInput' placeholder="模糊查询"/>*/}
                    <Descriptions.Item label="小组">
                      {dataDetail?.teamName}
                    </Descriptions.Item>
                  </Form.Item>

                  <Form.Item
                    style={{ width: 300 }}
                    label="组长"
                    name="teamLeader"
                    initialValue=""
                  >
                    <Descriptions.Item label="组长">
                      {dataDetail?.teamLeader}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="成员数"
                    name="studentNumbers"
                    initialValue=""
                  >
                    <Descriptions.Item className="tsdLabel" label="成员数">
                      {dataDetail?.studentNumbers}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{
                      width: 294,
                      overflow: 'hidden',
                      textOverflow: 'ellipsis',
                      whiteSpace: 'nowrap',
                    }}
                    label="成员"
                    name="teamMembers"
                    initialValue=""
                  >
                    <Descriptions.Item label="成员">
                      {teamMembers}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="院系"
                    name="collegesName"
                    initialValue=""
                  >
                    <Descriptions.Item label="院系">
                      {dataDetail?.collegesName}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="项目名称"
                    name="courseName"
                    initialValue=""
                  >
                    <Descriptions.Item label="项目名称">
                      {dataDetail?.courseName}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="实训老师"
                    name="teacher"
                    initialValue=""
                  >
                    <Descriptions.Item label="实训老师">
                      {teacher}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="责任老师"
                    name="responsibilityTeacher"
                    initialValue=""
                  >
                    <Descriptions.Item label="责任老师">
                      {dataDetail?.responsibilityTeacher}
                    </Descriptions.Item>
                  </Form.Item>

                  <Form.Item
                    style={{ width: 1000 }}
                    label="综合打分"
                    name="score"
                    initialValue=""
                  >
                    <Descriptions.Item label="综合打分">
                      {dataDetail?.score}
                    </Descriptions.Item>
                  </Form.Item>

                  <Form.Item
                    style={{ width: 300 }}
                    label="评语"
                    name="comments"
                    initialValue=""
                  >
                    <Descriptions.Item label="评语">
                      {dataDetail?.comments}
                    </Descriptions.Item>
                  </Form.Item>
                </Form>
              </>
            }
          </div>
        </div>
      </div>

      <Table
        style={{ width: '1500px' }}
        columns={[
          {
            title: '作业主题',
            dataIndex: 'title',
            align: 'center',
          },
          {
            title: '下发老师',
            dataIndex: 'teacherName',
            align: 'center',
          },
          {
            title: '下发时间',
            dataIndex: 'issuedTime',
            align: 'center',
          },
          {
            title: '提交时间',
            dataIndex: 'submitTime',
            align: 'center',
          },
          {
            title: '实际提交时间',
            dataIndex: 'actualSubmitTime',
            align: 'center',
          },
          {
            title: '提交情况',
            dataIndex: 'submitStatus',
            align: 'center',
          },
          {
            title: '作业得分',
            dataIndex: 'score',
            align: 'center',
          },

          {
            title: '操作',
            dataIndex: 'kind',
            align: 'center',
            render: (row: any) => (
              <>
                <Button type="link">详情</Button>
              </>
            ),
          },
        ]}
        dataSource={dataSource}
        size="middle"
      />
      <p>
        <Button>
          <Link to="../mark/personScore">返回</Link>
        </Button>
      </p>
    </>
  );
};
